package io.chenglicun.common.trans.util;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class TransContext {

    private static final Map<String, Boolean> NEED_TRANS_MAP = new ConcurrentHashMap<>();

    public static boolean needTrans(Method method) {
        return NEED_TRANS_MAP.getOrDefault(buildKey(method), Boolean.TRUE);
    }

    public static String buildKey(Method method) {
        return method.getDeclaringClass().getName() + "#" + method.getName();
    }

    public static void cancelTrans(Method method) {
        NEED_TRANS_MAP.put(buildKey(method), Boolean.FALSE);
    }

}
